﻿using MediatR;
using S_Incident.Domains.EventHandling;
using S_Incident.Infrasturctre.DapperInterface;
using S_Incident.Read.API.Application.Commands;

namespace S_Incident.Read.API.Application.CommandsHanders
{
    public class BindNodeCommandHanders : IRequestHandler<BindNodeCommand, List<BindNodeDto>>
    {
        private readonly IDapperNodeRepository dapperNode;
        public BindNodeCommandHanders(IDapperNodeRepository dapperNode)
        {
            this.dapperNode = dapperNode;       
        }
        /// <summary>
        /// 绑定下一级节点
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<List<BindNodeDto>> Handle(BindNodeCommand request, CancellationToken cancellationToken)
        {
            var smilt = " select * from Node";
            var from = await dapperNode.GetAllAsync(smilt);
            var bindNodeList=new List<BindNodeDto>();
            foreach (var nodeData in from)
            {
                bindNodeList.Add(new BindNodeDto
                {
                    value = nodeData.Id,
                    txt = nodeData.NodeType
                });
            }
            return bindNodeList;

        }
    }
}
